//
//  TargetView.m
//  eye_hunter
//
//  Created by cherry on 10-10-6.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "TargetView.h"
#import "MissionView.h"


@implementation TargetView

@synthesize target;
@synthesize isFound;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        isFound = NO;
		[self setUserInteractionEnabled:YES];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    MissionView *parent = (MissionView *)[self superview];
    CGPoint touchPoint = [[touches anyObject] locationInView:parent];
	if (!isFound) {
        isFound = [parent foundTarget:[self.target targetId]];
        if (isFound) {
            [parent playSound:@"hit_sound"];
            [parent showHitEffect:@"hit.png" In:touchPoint];
            parent.remain -= 1;
            int remains = parent.remain;
            if (remains == 0) {
                [parent allClear];
            }
            [self removeFromSuperview];
        }
	}
    if (!isFound) {
        [parent touchesBegan:touches withEvent:event];
    }
}

- (void)dealloc {
	[target dealloc];
    [super dealloc];
}


@end
